<template>
  <div class="stock-table" :style="`grid-template-columns: 163px repeat(${3}, 100px);`" v-if="props.isInput !== ''">
    <template v-if="props.takeStock === ''">
      <div v-for="(item, index) in list" :key="index" :style="index < 4 && 'background-color: #F7F7F7;font-weight: bold;'">
        <div v-if="(typeof item.value2 !== 'undefined')" class="stock-table__take-stock">
          {{ item.value1 }}/<span>{{ item.value2 }}</span>
        </div>
        <span v-else>{{ item.value1 }}</span>
      </div>
    </template>
    <template v-else>
      <div v-for="(item, index) in list" :key="index" :style="`${index < 4 && 'background-color: #F7F7F7;font-weight: bold;'};${!item && 'color: #999999;'}`">
        {{ item }}</div>
    </template>
  </div>
  <div class="stock-table" :style="`grid-template-columns: 163px repeat(${3}, 100px);`" v-else @click.stop="click">
    <div v-for="(item, index) in list" :key="index" :style="index < 4 && 'background-color: #F7F7F7;font-weight: bold;'">
      <template v-if="item.change">
        <input type="number" v-if="props.afterColor === ''" class="stock-table__value" :value="item.value" :style="item.corrected ? 'color:#1981F4' : 'color: #4A5060'" @focus="focus($event, index)" @blur="blur($event, item)" />
        <input type="number" v-else class="stock-table__value" :value="item.value" @focus="focus($event, index)" />
      </template>
      <span v-else>{{ item.value }}</span>
    </div>
  </div>
</template>
<script>
export default {
  inheritAttrs: false,
  props: ['isInput', 'afterColor', 'takeStock', 'list']
}
</script>
<script setup>
import { reactive, ref, onMounted } from "vue";
const props = defineProps();
const emits = defineEmits();
const list = reactive(props.list || []);

// const totalColumns = list.length / 3;

const click = () => {
  emits('change');
}
const focus = (e) => {
  emits('change');
}
const blur = (e, item) => {
  if (!item.corrected) {
    item.corrected = +e.target.value !== item.value;
  }
  item.value = +e.target.value
}

</script>
<style lang="less" scoped>
.stock-table {
  display: grid;
  grid-template-rows: 74px;
  grid-gap: 1px 1px;
  font-size: 26px;
  color: #2e323d;

  > div:first-child {
    position: relative;
    line-height: 1;
    &::before,
    &::after {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      color: #2e323d;
      box-sizing: border-box;
    }

    &::before {
      content: "尺码";
      text-align: right;
      padding: 11px 18px 0 0;
    }

    &::after {
      content: "颜色";
      padding-left: 16px;
      background: #e5e5e5;
      clip-path: polygon(0 0, 100% 100%, 0 100%);
      line-height: 100px;
    }
  }

  > div {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    box-shadow: 0 0 0 1px #dddee2;

    .stock-table__value {
      width: 88px;
      height: 62px;
      background: #ffffff;
      border: 1px solid #e5e5e5;
      border-radius: 10px;
      text-align: center;
    }

    .stock-table__value:focus {
      background: #ffffff;
      border: 1px solid #1981f4;
      box-shadow: 0px 0px 18px 0px rgba(0, 0, 0, 0.16);
      border-radius: 10px;
      text-align: center;
    }

    .stock-table__take-stock {
      font-size: 20px;
      font-weight: bold;
      color: #4a5060;

      > span {
        color: #1981f4;
      }
    }
  }
}
</style>